package com.ruoyi.web.controller.work;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.work.domain.WorkFill;
import com.ruoyi.work.service.IWorkFillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: MMDZ
 * @Desc: TODO 回退
 */
@RestController
@RequestMapping("/work/back")
public class WorkBackController extends BaseController {

    @Autowired
    private IWorkFillService workFillService;

    /**
     * 查询个人申报回退列表
     *
     * @param workFill
     * @return
     */
    @PreAuthorize("@ss.hasPermi('work:back:list')")
    @GetMapping("/list")
    public TableDataInfo list(WorkFill workFill) {
        startPage();
        List<WorkFill> list = workFillService.selectFillForRollBackList(workFill);
        return getDataTable(list);
    }

    /**
     * 申报回退 删除
     *
     * @param fillId
     * @return
     */
    @PreAuthorize("@ss.hasPermi('work:back:remove')")
    @Log(title = "申报回退-删除", businessType = BusinessType.DELETE)
    @DeleteMapping("/{fillId}")
    public AjaxResult remove(@PathVariable Long fillId) {
        return toAjax(workFillService.deleteWorkFillById(fillId));
    }

    /**
     * 申报回退 修改
     *
     * @param workFill
     * @return
     */
    @PreAuthorize("@ss.hasPermi('work:back:edit')")
    @Log(title = "申报回退-修改", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody WorkFill workFill) {
        return toAjax(workFillService.updateBackWorkFill(workFill));
    }

}
